package com.onec.service.netty.demo;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NettyDisCardHandler extends ChannelInboundHandlerAdapter {


    Logger log = LoggerFactory.getLogger(NettyDisCardHandler.class);

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;
        // 收到消息，丢弃如下
        try {
            while (byteBuf.isReadable()) {
                Byte b = byteBuf.readByte();
                log.info("收到小欸:{}", b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ReferenceCountUtil.release(msg);
        }

    }
}
